package study.lagou.com.mapper;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import study.lagou.com.pojo.Orders;
import study.lagou.com.pojo.User;

import java.util.List;

public interface IOrderMapper {

    @Select("select * from orders")
    @Results({
            @Result(id = true,property = "id", column = "id"),
            @Result(property = "ordertime", column = "ordertime"),
            @Result(property = "total", column = "total"),
            @Result(property = "user", column = "uid",javaType = User.class
                    ,one = @One(select = "study.lagou.com.mapper.IUserMapper.selectUserById"))
    })
    List<Orders> listAll();

    /**
     * 根据用户ID查询订单信息
     * @param userId
     * @return
     */
    @Select("select * from orders where uid = #{userId}")
    List<Orders> listOrderByUserId(String userId);
}
